package com.lehecai.core.api.game;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.game.*;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 游戏信息
 * @author chirowong
 */
public class GameInfo extends AbstractApiResultBean {

    public static final String GAME_ID = "game_id";
    public static final String GAME_TYPE = "game_type";
    public static final String GAME_STATUS = "game_status";
    public static final String GAME_GROUP = "game_group";
    public static final String GAME_SELL_STAUTS = "game_sell_status";
    public static final String GAME_FEATURE = "game_feature";
    public static final String GAME_RECHARGE_CREDIT = "game_recharge_credit";
    public static final String GAME_RECOMMEND = "game_recommend";
    public static final String GAME_SORT = "game_sort";
    public static final String GAME_NAME = "game_name";
    public static final String GAME_SHORT_NAME = "game_short_name";
    public static final String GAME_COMPANY = "game_company";
    public static final String GAME_URL = "game_url";
    public static final String GAME_TPL = "game_tpl";   
    public static final String GAME_DES = "game_des";    
    public static final String GAME_RECOMMEND_DES = "game_recommend_des";
    public static final String GAME_COMPANY_URL = "game_company_url";
    public static final String GAME_CARD_URL = "game_card_url";
    public static final String GAME_BBS_URL = "game_bbs_url";
    public static final String GAME_CMS_NOTICE = "game_cms_notice";
    public static final String GAME_CMS_RAIDER = "game_cms_raider";
    public static final String GAME_CMS_DATA = "game_cms_data";
    public static final String GAME_PLAY_WIDTH = "game_play_width";
    public static final String GAME_PLAY_HEIGHT = "game_play_height";
    public static final String GAME_CUSTOMER_SERVICE = "game_customer_service";
    public static final String GAME_LOGO_HOME = "game_logo_home";
    public static final String GAME_LOGO_RECOMMEND = "game_logo_recommend";
    public static final String GAME_LOGO_BACK = "game_logo_back";
    public static final String GAME_LOGO_SCREENSHOT_ONE = "game_logo_screenshot_1";
    public static final String GAME_LOGO_SCREENSHOT_TWO = "game_logo_screenshot_2";
    public static final String GAME_LOGO_SCREENSHOT_THREE = "game_logo_screenshot_3";

    private String gameId;                     	//游戏id
    private GameType gameType;                  //游戏
    private GameStatus gameStatus;              //游戏状态
    private GameGroup gameGroup;                //游戏类型
    private GameSellStatus gameSellStatus;      //游戏销售状态
    private YesNoStatus gameRecommend;          //是否推荐
    private GameFeature gameFeature;            //游戏特征
    private String gameRechargeCredit;         //是否允许使用彩贝 
    private String gameSort;                   	//游戏排序
    private String gameName;                    //游戏名称
    private String gameShortName;               //游戏缩写
    private String gameCompany;                 //运营商名称
    private String gameUrl;                   	//游戏地址
    private YesNoStatus gameTpl;				//是否使用单页模版
	private String gameDes;               		//长描述
    private String gameRecommendDes;      		//短描述
    private String gameCompanyUrl;    			//运营商url
    private String gameCardUrl;              	//新手卡地址
    private String gameBbsUrl;            		//论坛地址
    private String gameCmsNotice;           	//公告cms
    private String gameCmsRaider;       		//攻略cms
    private String gameCmsData;          		//资料cms
    private String gamePlayWidth;         		//游戏宽
    private String gamePlayHeight;       		//游戏高
    private String gameCustomerService;  		//客服
    private String gameLogoHome;          		//标准logo
    private String gameLogoRecommend;      		//推荐logo
    private String gameLogoBack;         		//单页大图
    private String gameLogoScreenshotOne;     	//截图1
    private String gameLogoScreenshotTwo;     	//截图2
    private String gameLogoScreenshotThree;    	//截图3

    public static GameInfo convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        GameInfo info = new GameInfo();
        JSONObject jsonObject = object.getJSONObject("game_ext");        
        
        info.gameId = getString(object, "game_id");
        info.setGameType(GameType.getItem(getInt(object, "game_type")));
        info.setGameStatus(GameStatus.getItem(getInt(object, "game_status")));
        info.setGameGroup(GameGroup.getItem(getInt(object, "game_group")));
        info.setGameSellStatus(GameSellStatus.getItem(getInt(object, "game_sell_status")));
        info.setGameRecommend(YesNoStatus.getItem(getInt(object, "game_recommend")));
        info.gameSort = getString(object, "game_sort");
        info.gameName = getString(object, "game_name");
        info.gameShortName = getString(object, "game_short_name");
        info.gameCompany = getString(object, "game_company");
        info.gameUrl = getString(object, "game_url");
        info.setGameTpl(YesNoStatus.getItem(getInt(object, "game_tpl")));
        
        if (!jsonObject.isNullObject()) {
        	info.gameDes = getString(jsonObject, "game_des");
            info.gameRecommendDes = getString(jsonObject, "game_recommend_des");
            info.gameCompanyUrl = getString(jsonObject, "game_company_url");
            info.gameCardUrl = getString(jsonObject, "game_card_url");
            info.gameBbsUrl = getString(jsonObject, "game_bbs_url");
            info.gameCmsNotice = getString(jsonObject, "game_cms_notice");
            info.gameCmsRaider = getString(jsonObject, "game_cms_raider");
            info.gameCmsData = getString(jsonObject, "game_cms_data");
            info.gamePlayWidth = getString(jsonObject, "game_play_width");
            info.gamePlayHeight = getString(jsonObject, "game_play_height");
            info.gameCustomerService = getString(jsonObject, "game_customer_service");
            info.gameLogoHome = getString(jsonObject, "game_logo_home");
            info.gameLogoRecommend = getString(jsonObject, "game_logo_recommend");
            info.gameLogoBack = getString(jsonObject, "game_logo_back");
            info.gameLogoScreenshotOne = getString(jsonObject, "game_logo_screenshot_1");
            info.gameLogoScreenshotTwo = getString(jsonObject, "game_logo_screenshot_2");
            info.gameLogoScreenshotThree = getString(jsonObject, "game_logo_screenshot_3");
            if (jsonObject.containsKey("game_feature")) {
            	info.setGameFeature(GameFeature.getItem(getInt(jsonObject, "game_feature")));
            }
            if (jsonObject.containsKey("game_recharge_credit")) {
            	info.setGameRechargeCredit(getString(jsonObject, "game_recharge_credit"));
            }
        }        
        return info;
    }

    public static List<GameInfo> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<GameInfo> list = new ArrayList<GameInfo>();

        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }

    public String getGameId() {
        return gameId;
    }

    public void setGameId(String gameId) {
        this.gameId = gameId;
    }

    public GameType getGameType() {
        return gameType;
    }

    public void setGameType(GameType gameType) {
        this.gameType = gameType;
    }

    public GameStatus getGameStatus() {
        return gameStatus;
    }

    public void setGameStatus(GameStatus gameStatus) {
        this.gameStatus = gameStatus;
    }

    public GameGroup getGameGroup() {
        return gameGroup;
    }

    public void setGameGroup(GameGroup gameGroup) {
        this.gameGroup = gameGroup;
    }

    public GameSellStatus getGameSellStatus() {
        return gameSellStatus;
    }

    public void setGameSellStatus(GameSellStatus gameSellStatus) {
        this.gameSellStatus = gameSellStatus;
    }

    public String getGameSort() {
        return gameSort;
    }

    public void setGameSort(String gameSort) {
        this.gameSort = gameSort;
    }

    public String getGameName() {
        return gameName;
    }

    public void setGameName(String gameName) {
        this.gameName = gameName;
    }

    public String getGameShortName() {
        return gameShortName;
    }

    public void setGameShortName(String gameShortName) {
        this.gameShortName = gameShortName;
    }

    public String getGameCompany() {
        return gameCompany;
    }

    public void setGameCompany(String gameCompany) {
        this.gameCompany = gameCompany;
    }

    public String getGameUrl() {
        return gameUrl;
    }

    public void setGameUrl(String gameUrl) {
        this.gameUrl = gameUrl;
    }

	
    public String getGameDes() {
        return gameDes;
    }

    public void setGameDes(String gameDes) {
        this.gameDes = gameDes;
    }

    public String getGameRecommendDes() {
        return gameRecommendDes;
    }

    public void setGameRecommendDes(String gameRecommendDes) {
        this.gameRecommendDes = gameRecommendDes;
    }

    public String getGameCompanyUrl() {
        return gameCompanyUrl;
    }

    public void setGameCompanyUrl(String gameCompanyUrl) {
        this.gameCompanyUrl = gameCompanyUrl;
    }

    public String getGameCardUrl() {
        return gameCardUrl;
    }

    public void setGameCardUrl(String gameCardUrl) {
        this.gameCardUrl = gameCardUrl;
    }

    public String getGameBbsUrl() {
        return gameBbsUrl;
    }

    public void setGameBbsUrl(String gameBbsUrl) {
        this.gameBbsUrl = gameBbsUrl;
    }

    public String getGameCmsNotice() {
        return gameCmsNotice;
    }

    public void setGameCmsNotice(String gameCmsNotice) {
        this.gameCmsNotice = gameCmsNotice;
    }

    public String getGameCmsRaider() {
        return gameCmsRaider;
    }

    public void setGameCmsRaider(String gameCmsRaider) {
        this.gameCmsRaider = gameCmsRaider;
    }

    public String getGameCmsData() {
        return gameCmsData;
    }

    public void setGameCmsData(String gameCmsData) {
        this.gameCmsData = gameCmsData;
    }

    public String getGamePlayWidth() {
        return gamePlayWidth;
    }

    public void setGamePlayWidth(String gamePlayWidth) {
        this.gamePlayWidth = gamePlayWidth;
    }

    public String getGamePlayHeight() {
        return gamePlayHeight;
    }

    public void setGamePlayHeight(String gamePlayHeight) {
        this.gamePlayHeight = gamePlayHeight;
    }

    public String getGameCustomerService() {
        return gameCustomerService;
    }

    public void setGameCustomerService(String gameCustomerService) {
        this.gameCustomerService = gameCustomerService;
    }

    public String getGameLogoHome() {
        return gameLogoHome;
    }

    public void setGameLogoHome(String gameLogoHome) {
        this.gameLogoHome = gameLogoHome;
    }

    public String getGameLogoRecommend() {
        return gameLogoRecommend;
    }

    public void setGameLogoRecommend(String gameLogoRecommend) {
        this.gameLogoRecommend = gameLogoRecommend;
    }

    public String getGameLogoBack() {
        return gameLogoBack;
    }

    public void setGameLogoBack(String gameLogoBack) {
        this.gameLogoBack = gameLogoBack;
    }

    public String getGameLogoScreenshotOne() {
        return gameLogoScreenshotOne;
    }

    public void setGameLogoScreenshotOne(String gameLogoScreenshotOne) {
        this.gameLogoScreenshotOne = gameLogoScreenshotOne;
    }

    public String getGameLogoScreenshotTwo() {
        return gameLogoScreenshotTwo;
    }

    public void setGameLogoScreenshotTwo(String gameLogoScreenshotTwo) {
        this.gameLogoScreenshotTwo = gameLogoScreenshotTwo;
    }

    public String getGameLogoScreenshotThree() {
        return gameLogoScreenshotThree;
    }

    public void setGameLogoScreenshotThree(String gameLogoScreenshotThree) {
        this.gameLogoScreenshotThree = gameLogoScreenshotThree;
    }

	public void setGameTpl(YesNoStatus gameTpl) {
		this.gameTpl = gameTpl;
	}

	public YesNoStatus getGameTpl() {
		return gameTpl;
	}

	public void setGameRecommend(YesNoStatus gameRecommend) {
		this.gameRecommend = gameRecommend;
	}

	public YesNoStatus getGameRecommend() {
		return gameRecommend;
	}

	public void setGameFeature(GameFeature gameFeature) {
		this.gameFeature = gameFeature;
	}

	public GameFeature getGameFeature() {
		return gameFeature;
	}

	public void setGameRechargeCredit(String gameRechargeCredit) {
		this.gameRechargeCredit = gameRechargeCredit;
	}

	public String getGameRechargeCredit() {
		return gameRechargeCredit;
	}

}
